home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / ecryptfs-mount-private < prev    next >
Encoding:
Text File  |  2009-06-04  |  2.0 KB  |  70 lines

  1. #!/bin/sh -e
  2. # This script mounts a user's confidential private folder
  3. #
  4. # Original by Michael Halcrow, IBM
  5. # Extracted to a stand-alone script by Dustin Kirkland <kirkland@canonical.com>
  6. #
  7. # This script:
  8. #  * interactively prompts for a user's wrapping passphrase (defaults to their
  9. #    login passphrase)
  10. #  * checks it for validity
  11. #  * unwraps a users mount passphrase with their supplied wrapping passphrase
  12. #  * inserts the mount passphrase into the keyring
  13. #  * and mounts a user's encrypted private folder
  14.  
  15. PRIVATE_DIR="Private"
  16. WRAPPING_PASS="LOGIN"
  17. PW_ATTEMPTS=3
  18. MESSAGE="Enter your login passphrase: "
  19.  
  20. if [ -f $HOME/.ecryptfs/wrapping-independent ]; then
  21.     # use a wrapping passphrase different from the login passphrase
  22.     WRAPPING_PASS="INDEPENDENT"
  23.     MESSAGE="Enter your wrapping passphrase: "
  24. fi
  25.  
  26. WRAPPED_PASSPHRASE_FILE="$HOME/.ecryptfs/wrapped-passphrase"
  27. MOUNT_PASSPHRASE_SIG_FILE="$HOME/.ecryptfs/$PRIVATE_DIR.sig"
  28.  
  29. # First, silently try to perform the mount, which would succeed if the appropriate
  30. # key is available in the keyring
  31. if /sbin/mount.ecryptfs_private >/dev/null 2>&1; then
  32.     exit 0
  33. fi
  34.  
  35. # Otherwise, interactively prompt for the user's password
  36. if [ -f "$WRAPPED_PASSPHRASE_FILE" -a -f "$MOUNT_PASSPHRASE_SIG_FILE" ]; then
  37.     tries=0
  38.     stty_orig=`stty -g`
  39.     while [ $tries -lt $PW_ATTEMPTS ]; do
  40.         echo -n "$MESSAGE"
  41.         stty -echo
  42.         LOGINPASS=`head -n1`
  43.         stty $stty_orig
  44.         echo
  45.         if printf "%s\0" "$LOGINPASS" | ecryptfs-insert-wrapped-passphrase-into-keyring "$WRAPPED_PASSPHRASE_FILE" - ; then
  46.             break
  47.         else
  48.             echo "ERROR: Your passphrase is incorrect"
  49.             tries=$(($tries + 1))
  50.             continue
  51.         fi
  52.     done
  53.     if [ $tries -ge $PW_ATTEMPTS ]; then
  54.         echo "ERROR: Too many incorrect password attempts, exiting"
  55.         exit 1
  56.     fi
  57.     /sbin/mount.ecryptfs_private
  58. else
  59.     echo "ERROR: Encrypted $PRIVATE_DIR is not setup properly"
  60.     exit 1
  61. fi
  62. if grep -qs "$HOME/.Private $PWD ecryptfs " /proc/mounts 2>/dev/null; then
  63.     echo
  64.     echo "INFO: Your private directory has been mounted."
  65.     echo "INFO: To see this change in your current shell:"
  66.     echo "  cd $PWD"
  67.     echo
  68. fi
  69. exit 0
  70.